//
// Created by Administrator on 2021/12/30.
//

#ifndef CPP_LEARNING_LIST_NODE_HPP
#define CPP_LEARNING_LIST_NODE_HPP
#include <iostream>
typedef int Rank;
#define ListNodePosi(T) ListNode<T>* //列表节点指针

template <typename T>
struct ListNode{
    T data;
    ListNodePosi(T) pred; // 前驱
    ListNodePosi(T) succ; // 后继

    ListNode(){}
    ListNode(T&e, ListNodePosi(T) p = NULL, ListNodePosi(T) s = NULL):data(e),pred(p),succ(s){

    }

    ListNodePosi(T) insertAsPred(T const &e);
    ListNodePosi(T) insertAsSucc(T const &e);
};

template <typename T>
ListNode<T> * ListNode<T>::insertAsPred(const T &e) {
    ListNodePosi(T) _pred = this->pred;
    this->pred = new ListNode<T>(e,_pred,this);
    _pred->succ = this->pred;
    return this->pred;
}

template <typename T>
ListNode<T> * ListNode<T>::insertAsSucc(const T &e) {
    ListNodePosi(T) _succ = this->succ;
    this->succ = new ListNode<T>(e,this,_succ);
    _succ->pred = this->succ;
    return this->succ;
}


#endif //CPP_LEARNING_LIST_NODE_HPP
